﻿using System;

namespace AutoDb {
	/// <summary>
	/// 
	/// </summary>
	static class CodeTemplateFactory {
		/// <summary>
		/// 
		/// </summary>
		/// <param name="fileType"></param>
		/// <param name="target"></param>
		/// <param name="logContext"></param>
		/// <returns></returns>
		public static ICodeTemplate CreateTemplate(CodeFileType fileType, string target, LogContext logContext) {
			var fullPath = System.IO.Path.GetFullPath(target);
			if (System.IO.File.Exists(fullPath)) {
				throw new InvalidOperationException(Properties.Main.ErrorSameNameFileExists);
			}

			if (!System.IO.Directory.Exists(fullPath)) {
				System.IO.Directory.CreateDirectory(fullPath);
			}

			switch (fileType) {
				case CodeFileType.CSharp:
					return new CSharpCodeTemplate(fullPath, logContext);
				default:
					throw new InvalidProgramException();
			}
		}
	} // end of CodeTemplateFactory.
}
